<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>配置 | MyUI 4.x</title>
    <meta name="generator" content="VuePress 1.7.1">
    <link rel="icon" href="/my/favicon.ico">
    <script>
      var _hmt = _hmt || [];
      (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?c4e5f73318b5cb0c389e3d9a05f831cc";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>
    <meta name="description" content="MyUI是美亚柏科旗下新德汇出品的Web前端一站式项目工程框架，专注于公检法行业中台系统快速搭建，框架已在多个项目实战检验。">
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    
    <link rel="preload" href="/my/assets/css/0.styles.82a18d97.css" as="style"><link rel="preload" href="/my/assets/js/app.fc4964fc.js" as="script"><link rel="preload" href="/my/assets/js/513.edb84f11.js" as="script"><link rel="preload" href="/my/assets/js/1382.9218af0f.js" as="script">
    <link rel="stylesheet" href="/my/assets/css/0.styles.82a18d97.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/my/" class="home-link router-link-active"><img src="/my/img/logo.png" alt="MyUI 4.x" class="logo"> <span class="site-name can-hide">MyUI 4.x</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/my/guide/" class="nav-link router-link-active">
  指南
</a></div><div class="nav-item"><a href="/my/ui/components/" class="nav-link">
  组件
</a></div><div class="nav-item"><a href="/my/ui/charts/" class="nav-link">
  图表
</a></div><div class="nav-item"><a href="/my/ui/map/" class="nav-link">
  地图
</a></div><div class="nav-item"><a href="/my/ui/go/" class="nav-link">
  关系图
</a></div><div class="nav-item"><a href="/my/ui/icon/" class="nav-link">
  图标
</a></div><div class="nav-item"><a href="/my/ui/pages/" class="nav-link">
  页面
</a></div><div class="nav-item"><a href="http://newgateway.gitee.io/my-web/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  演示
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="JSDoc" class="dropdown-title"><span class="title">JSDoc</span> <span class="arrow down"></span></button> <button type="button" aria-label="JSDoc" class="mobile-dropdown-title"><span class="title">JSDoc</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/my/api/components.html" class="nav-link">
  基础组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/utils.html" class="nav-link">
  工具函数
</a></li><li class="dropdown-item"><!----> <a href="/my/api/charts.html" class="nav-link">
  图表组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/map.html" class="nav-link">
  地图组件
</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/my/guide/" class="nav-link router-link-active">
  指南
</a></div><div class="nav-item"><a href="/my/ui/components/" class="nav-link">
  组件
</a></div><div class="nav-item"><a href="/my/ui/charts/" class="nav-link">
  图表
</a></div><div class="nav-item"><a href="/my/ui/map/" class="nav-link">
  地图
</a></div><div class="nav-item"><a href="/my/ui/go/" class="nav-link">
  关系图
</a></div><div class="nav-item"><a href="/my/ui/icon/" class="nav-link">
  图标
</a></div><div class="nav-item"><a href="/my/ui/pages/" class="nav-link">
  页面
</a></div><div class="nav-item"><a href="http://newgateway.gitee.io/my-web/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  演示
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="JSDoc" class="dropdown-title"><span class="title">JSDoc</span> <span class="arrow down"></span></button> <button type="button" aria-label="JSDoc" class="mobile-dropdown-title"><span class="title">JSDoc</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/my/api/components.html" class="nav-link">
  基础组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/utils.html" class="nav-link">
  工具函数
</a></li><li class="dropdown-item"><!----> <a href="/my/api/charts.html" class="nav-link">
  图表组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/map.html" class="nav-link">
  地图组件
</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>开发指南</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/my/guide/access.html" class="sidebar-link">权限控制</a></li><li><a href="/my/guide/app.html" class="sidebar-link">子应用微服务</a></li><li><a href="/my/guide/cmd.html" class="sidebar-link">脚本命令</a></li><li><a href="/my/guide/coder.html" class="sidebar-link">代码生成器</a></li><li><a href="/my/guide/config.html" aria-current="page" class="active sidebar-link">配置</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/my/guide/config.html#my-config-js" class="sidebar-link">my.config.js</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/my/guide/config.html#publicpath" class="sidebar-link">publicPath</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#entry" class="sidebar-link">entry</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#devserverport" class="sidebar-link">devServerPort</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#devserverproxy" class="sidebar-link">devServerProxy</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#previewserverport" class="sidebar-link">previewServerPort</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#outputdir" class="sidebar-link">outputDir</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#assetsdir" class="sidebar-link">assetsDir</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#extendcontentbase" class="sidebar-link">extendContentBase</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#lintonsave" class="sidebar-link">lintOnSave</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#prefetch" class="sidebar-link">prefetch</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#dll" class="sidebar-link">dll</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#docsdevport" class="sidebar-link">docsDevPort</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#docsbaseurl" class="sidebar-link">docsBaseUrl</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#docsoutputdir" class="sidebar-link">docsOutputDir</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#autoroutes" class="sidebar-link">autoRoutes</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#serverport" class="sidebar-link">serverPort</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#staticconfig" class="sidebar-link">staticConfig</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#coder" class="sidebar-link">coder</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#transpiledependencies" class="sidebar-link">transpileDependencies</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#productionsourcemap" class="sidebar-link">productionSourceMap</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#mock" class="sidebar-link">mock</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#microapp" class="sidebar-link">microApp</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#chainwebpack" class="sidebar-link">chainWebpack</a></li></ul></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#ui-config" class="sidebar-link">ui/config</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/my/guide/config.html#debug" class="sidebar-link">debug</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#appname" class="sidebar-link">appName</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#routeprefix" class="sidebar-link">routePrefix</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#router" class="sidebar-link">router</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#autoroutes-2" class="sidebar-link">autoRoutes</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#vuex" class="sidebar-link">vuex</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#keys" class="sidebar-link">keys</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#statuscode" class="sidebar-link">statusCode</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#axios" class="sidebar-link">axios</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#svg" class="sidebar-link">svg</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#mock-2" class="sidebar-link">mock</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#microapp-2" class="sidebar-link">microApp</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#analysis" class="sidebar-link">analysis</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#access" class="sidebar-link">access</a></li></ul></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#install" class="sidebar-link">install</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/my/guide/config.html#type" class="sidebar-link">type</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#branch" class="sidebar-link">branch</a></li><li class="sidebar-sub-header"><a href="/my/guide/config.html#repository" class="sidebar-link">repository</a></li></ul></li></ul></li><li><a href="/my/guide/constant.html" class="sidebar-link">常量和静态配置</a></li><li><a href="/my/guide/extension.html" class="sidebar-link">内置实例扩展</a></li><li><a href="/my/guide/route.html" class="sidebar-link">自动配置路由</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>内置资源</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>进阶教程</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>第三方类库</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="配置"><a href="#配置" class="header-anchor">#</a> 配置</h1> <p><code>My</code> 遵循约定大于配置的原则，<code>MyWeb</code>工程模板默认已是最佳的实践配置，能满足绝大部分的应用场景， 通常不需要修改配置。
但也避免不了会出现特殊的情况，因此<code>My</code>也提供了几种方式的配置。</p> <h2 id="my-config-js"><a href="#my-config-js" class="header-anchor">#</a> my.config.js</h2> <p><code>my.config.js</code> 是工程配置，即对开发环境、编译、辅助工具等与项目实现功能或业务无关的配置。</p> <p>配置文件名必须为 <code>my.config.js</code>, 并且只能放置在项目工程根目录下， 如果不存在该文件可以手动新建。</p> <p>文件用<code>js</code>编写，采用CommonJS规范导出模块。如：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
  devServerPort<span class="token operator">:</span> <span class="token number">8000</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="publicpath"><a href="#publicpath" class="header-anchor">#</a> publicPath</h3> <p>部署应用时的基本 URL, 与 <code>vue-cli</code> 的 <code>publicPath</code> 配置一样。
默认：'/'</p> <h3 id="entry"><a href="#entry" class="header-anchor">#</a> entry</h3> <p><code>Webpack</code> 配置的入口文件路径， 默认：'./src/main.js'</p> <h3 id="devserverport"><a href="#devserverport" class="header-anchor">#</a> devServerPort</h3> <p>开发环境启动端口号，默认: 8000</p> <h3 id="devserverproxy"><a href="#devserverproxy" class="header-anchor">#</a> devServerProxy</h3> <p>开发环境代理配置, 默认：null
如果你的前端应用和后端 API 服务器没有运行在同一个主机上，你需要在开发环境下将 API 请求代理到 API 服务器。</p> <p>建议还是由后端解决接口跨域问题。</p> <p>配置示例：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
  devServerProxy<span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token string">'/api'</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        target<span class="token operator">:</span> <span class="token string">'&lt;url&gt;'</span><span class="token punctuation">,</span>
        ws<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
        changeOrigin<span class="token operator">:</span> <span class="token boolean">true</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token string">'/foo'</span><span class="token operator">:</span> <span class="token punctuation">{</span>
        target<span class="token operator">:</span> <span class="token string">'&lt;other_url&gt;'</span>
      <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><div class="custom-block warning"><p class="custom-block-title">注意</p> <p>不能设置为空对象 {}</p></div> <h3 id="previewserverport"><a href="#previewserverport" class="header-anchor">#</a> previewServerPort</h3> <p>预览服务器端口，默认：7000</p> <h3 id="outputdir"><a href="#outputdir" class="header-anchor">#</a> outputDir</h3> <p>生成的生产环境构建文件的目录， 默认：dist</p> <h3 id="assetsdir"><a href="#assetsdir" class="header-anchor">#</a> assetsDir</h3> <p>放置生成的静态资源 (js、css、img、fonts) 的 (相对于 outputDir 的) 目录。
默认：assets</p> <h3 id="extendcontentbase"><a href="#extendcontentbase" class="header-anchor">#</a> extendContentBase</h3> <p>扩展的静态资源目录，数组形式，支持多个，只对主站有效。默认：[]</p> <h3 id="lintonsave"><a href="#lintonsave" class="header-anchor">#</a> lintOnSave</h3> <p>是否在开发环境下通过 eslint-loader 在每次保存时 lint 代码， 默认：error</p> <p>设置为 true 时，eslint-loader 会将 lint 错误输出为编译警告。默认情况下，警告仅仅会被输出到命令行，且不会使得编译失败。</p> <p>如果你希望让 lint 错误在开发时直接显示在浏览器中，你可以使用 lintOnSave: 'error'。这会强制 eslint-loader 将 lint 错误输出为编译错误，同时也意味着 lint 错误将会导致编译失败。</p> <h3 id="prefetch"><a href="#prefetch" class="header-anchor">#</a> prefetch</h3> <p>开启预加载，页面加载完成后，利用空闲时间提前获取用户未来可能会访问的内容。默认：true</p> <p>Prefetch 链接将会消耗带宽。
如果你的应用很大且有很多 async chunk，而用户主要使用的是对带宽较敏感的移动端，
那么你可能需要关掉 prefetch 链接并手动选择要提前获取的代码区块。</p> <h3 id="dll"><a href="#dll" class="header-anchor">#</a> dll</h3> <p>生产环境打包dll。默认：['vue', 'vue-router', 'vuex', 'axios', 'path-to-regexp', 'nprogress', 'qiankun']</p> <h3 id="docsdevport"><a href="#docsdevport" class="header-anchor">#</a> docsDevPort</h3> <p>文档开发环境启动端口号。默认：3001</p> <h3 id="docsbaseurl"><a href="#docsbaseurl" class="header-anchor">#</a> docsBaseUrl</h3> <p>文档部署目录。默认：'/my/'</p> <h3 id="docsoutputdir"><a href="#docsoutputdir" class="header-anchor">#</a> docsOutputDir</h3> <p>文档编译输出目录。默认：web</p> <h3 id="autoroutes"><a href="#autoroutes" class="header-anchor">#</a> autoRoutes</h3> <p>自动生成路由配置。默认： true</p> <h3 id="serverport"><a href="#serverport" class="header-anchor">#</a> serverPort</h3> <p>服务端启动端口号，默认：7001</p> <h3 id="staticconfig"><a href="#staticconfig" class="header-anchor">#</a> staticConfig</h3> <p>开启静态配置。默认：true</p> <h3 id="coder"><a href="#coder" class="header-anchor">#</a> coder</h3> <p>代码生成器配置对象。请参考<a href="/my/guide/coder.html">代码生成器</a></p> <h3 id="transpiledependencies"><a href="#transpiledependencies" class="header-anchor">#</a> transpileDependencies</h3> <p>默认情况下 babel-loader 会忽略所有 node_modules 中的文件。如果你想要通过 Babel 显式转译一个依赖，可以在这个选项中列出来。</p> <p>默认：['@xdh/my']</p> <h3 id="productionsourcemap"><a href="#productionsourcemap" class="header-anchor">#</a> productionSourceMap</h3> <p>生成环境是否生成SourceMap, 默认不生成</p> <h3 id="mock"><a href="#mock" class="header-anchor">#</a> mock</h3> <p>开启模拟支持，默认值： process.env.NODE_ENV !== 'production'， 默认在开发环境下开启</p> <h3 id="microapp"><a href="#microapp" class="header-anchor">#</a> microApp</h3> <p>开启微应用支持，默认：false
在项目不需要做主应用时，建议关闭，设置为false，可高减少打包文件体积，提高性能。</p> <h3 id="chainwebpack"><a href="#chainwebpack" class="header-anchor">#</a> chainWebpack</h3> <p>Webpack自定义配置。</p> <p>是一个函数，会接收一个基于 <a href="https://github.com/mozilla-neutrino/webpack-chain" target="_blank" rel="noopener noreferrer">webpack-chain<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 的 <code>ChainableConfig</code> 实例。允许对内部的 <code>webpack</code> 配置进行更细粒度的修改。</p> <p>更多细节可查阅：配合 <a href="https://cli.vuejs.org/zh/guide/webpack.html#%E9%93%BE%E5%BC%8F%E6%93%8D%E4%BD%9C-%E9%AB%98%E7%BA%A7" target="_blank" rel="noopener noreferrer">webpack &gt; 链式操作<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <h2 id="ui-config"><a href="#ui-config" class="header-anchor">#</a> ui/config</h2> <p><code>ui/config</code> 是项目的运行时配置。支持获取和设置。项目的源码目录 <code>@/config.js</code> 文件就是用来设置 <code>ui/config</code></p> <p>设置：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> <span class="token punctuation">{</span><span class="token keyword">set</span> <span class="token keyword">as</span> setConfig<span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'$ui/config'</span>

<span class="token function">setConfig</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  router<span class="token operator">:</span> <span class="token punctuation">{</span>
    mode<span class="token operator">:</span> <span class="token string">'hash'</span><span class="token punctuation">,</span>
    base<span class="token operator">:</span> <span class="token string">'/'</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p>获取：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> config <span class="token keyword">from</span> <span class="token string">'$ui/config'</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>config<span class="token punctuation">.</span>router<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="debug"><a href="#debug" class="header-anchor">#</a> debug</h3> <p>开启debug模式，默认在开发模式开启，在产品模式关闭。关闭后 Vue实例内置与<code>$log</code>相关的方法不再打印信息。</p> <h3 id="appname"><a href="#appname" class="header-anchor">#</a> appName</h3> <p>子应用名称</p> <h3 id="routeprefix"><a href="#routeprefix" class="header-anchor">#</a> routePrefix</h3> <p>路由path前缀，只对hash模式的子应用有效</p> <h3 id="router"><a href="#router" class="header-anchor">#</a> router</h3> <p>实例化VueRouter 参数选项对象，有2个属性 {mode, base}</p> <h4 id="mode"><a href="#mode" class="header-anchor">#</a> mode</h4> <p>路由模式，可选值：hash / history ， 默认：hash</p> <h4 id="base"><a href="#base" class="header-anchor">#</a> base</h4> <p>应用的基路径。例如，如果整个单页应用服务在 /app/ 下，然后 base 就应该设为 &quot;/app/&quot;</p> <h3 id="autoroutes-2"><a href="#autoroutes-2" class="header-anchor">#</a> autoRoutes</h3> <p>应用自动创建的路由表配置，默认: true</p> <h3 id="vuex"><a href="#vuex" class="header-anchor">#</a> vuex</h3> <p>Vuex实例化参数配置</p> <h4 id="strict"><a href="#strict" class="header-anchor">#</a> strict</h4> <p>进入严格模式，默认：true， 在严格模式下，任何 mutation 处理函数以外修改 Vuex state 都会抛出错误。</p> <h3 id="keys"><a href="#keys" class="header-anchor">#</a> keys</h3> <p>属性名映射 用来适配前后端接口交互参数和响应数据字段名称。</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>  keys<span class="token operator">:</span> <span class="token punctuation">{</span>
    code<span class="token operator">:</span> <span class="token string">'code'</span><span class="token punctuation">,</span>    <span class="token comment">// 响应状态码 </span>
    data<span class="token operator">:</span> <span class="token string">'data'</span><span class="token punctuation">,</span>    <span class="token comment">// 响应数据</span>
    message<span class="token operator">:</span> <span class="token string">'msg'</span><span class="token punctuation">,</span>  <span class="token comment">// 错误信息</span>
    total<span class="token operator">:</span> <span class="token string">'total'</span><span class="token punctuation">,</span>  <span class="token comment">// 记录数</span>
    list<span class="token operator">:</span> <span class="token string">'list'</span><span class="token punctuation">,</span>    <span class="token comment">// 列表数据</span>
    page<span class="token operator">:</span> <span class="token string">'page'</span><span class="token punctuation">,</span>    <span class="token comment">// 页码</span>
    limit<span class="token operator">:</span> <span class="token string">'limit'</span><span class="token punctuation">,</span>  <span class="token comment">// 每页几条</span>
    pages<span class="token operator">:</span> <span class="token string">'pages'</span>   <span class="token comment">// 总页数</span>
  <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><h3 id="statuscode"><a href="#statuscode" class="header-anchor">#</a> statusCode</h3> <p>请求响应状态码</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>  statusCode<span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token comment">// 响应成功</span>
    success<span class="token operator">:</span> <span class="token number">200</span><span class="token punctuation">,</span>
    
    <span class="token comment">// 未登录, 或登录失效</span>
    notLogin<span class="token operator">:</span> <span class="token number">401</span><span class="token punctuation">,</span>
    
    <span class="token comment">// 权限不足</span>
    authorize<span class="token operator">:</span> <span class="token number">403</span><span class="token punctuation">,</span>
    
    <span class="token comment">// 系统内部错误</span>
    error<span class="token operator">:</span> <span class="token number">500</span>
  <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h3 id="axios"><a href="#axios" class="header-anchor">#</a> axios</h3> <p>axios 实例配置</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>  axios<span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token comment">/**
     * 请求头
     */</span>
    headers<span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token string">'Content-Type'</span><span class="token operator">:</span> <span class="token string">'application/json;charset=UTF-8'</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token comment">/**
     * 超时时间
     */</span>
    timeout<span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
    <span class="token comment">/**
     * 携带验证
     */</span>
    withCredentials<span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
    <span class="token comment">/**
     * 响应数据类型
     */</span>
    responseType<span class="token operator">:</span> <span class="token string">'json'</span><span class="token punctuation">,</span>
    <span class="token comment">/**
     * 请求内容长度
     */</span>
    maxContentLength<span class="token operator">:</span> <span class="token operator">-</span><span class="token number">1</span>
  <span class="token punctuation">}</span>
 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div><h3 id="svg"><a href="#svg" class="header-anchor">#</a> svg</h3> <p>svg图标配置</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>  svg<span class="token operator">:</span> <span class="token punctuation">{</span>
    viewBox<span class="token operator">:</span> <span class="token string">'0 0 1024 1024'</span><span class="token punctuation">,</span>
    width<span class="token operator">:</span> <span class="token string">'1em'</span><span class="token punctuation">,</span>
    height<span class="token operator">:</span> <span class="token string">'1em'</span><span class="token punctuation">,</span>
    fill<span class="token operator">:</span> <span class="token string">'currentColor'</span>
  <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h3 id="mock-2"><a href="#mock-2" class="header-anchor">#</a> mock</h3> <p>配置模拟数据实例化参数， 可以是 <code>Object</code> 或 <code>Boolean</code>。 改配置只对开发模式下有效，生产模式不加载模拟数据。</p> <p>对象形式配置超时：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token punctuation">{</span>
  timeout<span class="token operator">:</span> <span class="token string">'200-500'</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="microapp-2"><a href="#microapp-2" class="header-anchor">#</a> microApp</h3> <p>应用微服务启动配置参数，默认值：</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token punctuation">{</span>
    <span class="token comment">// 是否开启预加载，默认为 true。</span>
    prefetch<span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
    <span class="token comment">//  可选，是否为单实例场景，默认为 true</span>
    singular<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
    <span class="token comment">// 可选，是否开启沙箱，默认为 true, 在开发环境开启sandbox时加载子应用切换主题，热更新会报错</span>
    sandbox<span class="token operator">:</span> process<span class="token punctuation">.</span>env<span class="token punctuation">.</span><span class="token constant">NODE_ENV</span> <span class="token operator">===</span> <span class="token string">'production'</span>
  <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h3 id="analysis"><a href="#analysis" class="header-anchor">#</a> analysis</h3> <p>启用统计埋点，默认：false</p> <h3 id="access"><a href="#access" class="header-anchor">#</a> access</h3> <p>权限实例化参数， 参考 <a href="/my/guide/access.html#配置">权限控制</a></p> <h2 id="install"><a href="#install" class="header-anchor">#</a> install</h2> <p>在非互联网环境安装依赖需要把 node_modules 部署到内网<code>git</code> 或 <code>svn</code>， 然后配置 <code>package.json</code></p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>

  <span class="token property">&quot;install&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;git&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;branch&quot;</span><span class="token operator">:</span> <span class="token string">&quot;master&quot;</span><span class="token punctuation">,</span>
    <span class="token property">&quot;repository&quot;</span><span class="token operator">:</span> <span class="token string">&quot;https://gitee.com/newgateway/node_modules.git&quot;</span>
  <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h3 id="type"><a href="#type" class="header-anchor">#</a> type</h3> <p>仓库类型 <code>git</code> 或 <code>svn</code></p> <h3 id="branch"><a href="#branch" class="header-anchor">#</a> branch</h3> <p>分支名称，仅对 <code>git</code> 有效</p> <h3 id="repository"><a href="#repository" class="header-anchor">#</a> repository</h3> <p>仓库地址</p></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/my/guide/coder.html" class="prev">
        代码生成器
      </a></span> <span class="next"><a href="/my/guide/constant.html">
        常量和静态配置
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/my/assets/js/app.fc4964fc.js" defer></script><script src="/my/assets/js/513.edb84f11.js" defer></script><script src="/my/assets/js/1382.9218af0f.js" defer></script>
  </body>
</html>
